package com.hehongdan.cpp

import org.junit.Test

/**
 * 类描述：
 *
 * @author HeHongdan
 * @date 2020/6/29
 * @version v2020/6/29
 */
class ClassTest {

    val lizi = Lizi()

    val a = Lizi::class//KClass<Lizi>
    val b = lizi::class//KClass<out Lizi>

    val c = Lizi::class.java//Class<Lizi>
    val d = lizi::class.java//Class<out Lizi>

    val e = Lizi::javaClass//val e: KProperty1<Lizi, Class<Lizi>
    val f = lizi::javaClass//val f: KProperty0<Class<Lizi>>

    val g = Lizi.javaClass//val g: Class<Lizi.Companion>, 这里获取的是伴生类的class，属性都在原类
    val h = lizi.javaClass//val h: Class<Lizi>//这里获取的是 Lizi 类的 class

    val i = Lizi.javaClass.kotlin//val i: KClass<Lizi.Companion>
    val j = lizi.javaClass.kotlin//val j: KClass<Lizi>

    @Test
    fun test1() {
        println(
            "Lizi::class= " + a
                    + "\nlizi::class= " + b

                    + "\n\nLizi::class.java= " + c
                    + "\nlizi::class.java= " + d

                    + "\n\nLizi::javaClass= " + e
                    + "\nlizi::javaClass= " + f

                    + "\n\nLizi.javaClass= " + g
                    + "\nlizi.javaClass= " + h

                    + "\n\nLizi.javaClass.kotlin= " + i
                    + "\nlizi.javaClass.kotlin= " + j
        )

        println(
            "\n\n\n获取Java的Class实例"
                    + "\nLizi::class.java= " + c
                    + "\n或\nlizi::javaClass= " + h


                    + "\n\n获取Kotlin的Class实例lizi.javaClass.kotlin= " + j
        )
    }

}